<script lang="ts" setup>
import useStore from '@/store';
import { storeToRefs } from 'pinia';
import { watchEffect } from 'vue';
import { useRoute } from 'vue-router';
import GoodsImage from './components/goods-image.vue';
import GoodsSales from './components/goods-sales.vue';
import GoodsName from './components/goods-name.vue';
const {Goods} = useStore()
const route = useRoute()
const { info } = storeToRefs(Goods)
// 调用接口
watchEffect(()=>{
    const id = route.params.id as string
    if (!route.params.id) return
    Goods.resetInfo()
    Goods.getGoodsInfo(id)
})

</script>
<template>
  <div class="xtx-goods-page">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBread v-if="info.categories">
        <BreadItem to="/">首页</BreadItem>
        <BreadItem :to="`/category/${info.categories[1].id }`">{{info.categories[1].name}}</BreadItem>
        <BreadItem :to="`/category/sub/${info.categories[0].id }`">{{info.categories[0].name}}</BreadItem>
        <BreadItem to="/">{{info.name }}</BreadItem>
      </XtxBread>
     <!-- 商品信息 -->
<div  v-if="info.mainPictures" class="goods-info">
  <div class="media">
   <GoodsImage :images="info.mainPictures"></GoodsImage>
   <GoodsSales></GoodsSales>
  </div>
  <div class="spec">
    <GoodsName :goods="info"></GoodsName>
  </div>
</div>
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs"></div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside"></div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>